package test2;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        //1. 通过Class对象的方法创建。
        Class clazz = Class.forName("test2.Student");
        Student stu1 = (Student) clazz.newInstance();

        //2. 通过Constructor对象的方法创建。
        Constructor constructor = clazz.getConstructor();
        Student stu2 = (Student) constructor.newInstance();
    }
}
